package com.pipidan.blog.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pipidan.blog.dao.FriendLinkDao;
import com.pipidan.blog.entity.FriendLink;
import com.pipidan.blog.mapper.FriendLinkMapper;
import com.pipidan.blog.service.FriendLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Date: Created in 11:28 2020/6/14
 * @Author: ONESTAR
 * @QQ群: 530311074
 * @URL: https://onestar.newstar.net.cn/
 */
@Service
public class FriendLinkServiceImpl implements FriendLinkService {
    @Autowired
    private FriendLinkMapper friendLinkMapper;

    @Override
    @Cacheable(value = "friendlinkList",key = "'friendlink'")       // redis缓存
    public List<FriendLink> listFriendLink() {
        LambdaQueryWrapper<FriendLink> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(FriendLink::getCreateTime);
        return friendLinkMapper.selectList(wrapper);
    }

    @Override
    public int saveFriendLink(FriendLink friendLink) {
        return  friendLinkMapper.insert(friendLink);
    }

    @Override
    public FriendLink getFriendLinkByBlogaddress(String blogaddress) {
        LambdaQueryWrapper<FriendLink> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FriendLink::getBlogaddress,blogaddress);
        return friendLinkMapper.selectOne(wrapper);
    }

    @Override
    public FriendLink getFriendLink(Long id) {
        return friendLinkMapper.selectById(id);
    }

    @Override
    public int updateFriendLink(FriendLink friendLink) {
        return friendLinkMapper.updateById(friendLink);
    }

    @Override
    public void deleteFriendLink(Long id) {
        friendLinkMapper.deleteById(id);
    }
}